﻿@model IEnumerable<Backend.JYD.Model.Task.IntentEntryInfo>
@using Backend.JYD.Business
@using Backend.JYD.Model
@using Backend.JYD.BLL
@using Backend.JYD.Web.Common
@{
    ViewBag.Title = "我的意向管理";
    ViewBag.CurrMenu = "mu01";
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#txtStartDate").focus(function () {
            WdatePicker();
        });
        $("#txtEndDate").focus(function () {
            WdatePicker();
        });
    });
</script>

<div class="frame-tit">
    <span class="ico-left"></span>
    <div class="title">@ViewBag.Title</div>
    <span class="ico-right"></span>
    <div class="title-side blu line">
    </div>
</div>
<div class="frame-cont">
    <h2>查询条件</h2>
    <p>
    录入时间：
        <input  type="text" name="txtStartDate" id="txtStartDate" value="@ViewBag.StartDate"  readonly="readonly"  class="wid100"/>
        至
        <input  type="text" name="txtEndDate" id="txtEndDate" value="@ViewBag.EndDate"  readonly="readonly"  class="wid100"/>
    </p>
    <p>
        意向状态：
        <select name="ddlStatus" id="ddlStatus" class="wid100">
            <option value="-1">全部</option>
            <option value="1" @(ViewBag.Status == 1 ? "selected=\"selected\"" : string.Empty)>未提交</option>
            <option value="2" @(ViewBag.Status == 2 ? "selected=\"selected\"" : string.Empty)>已提交</option>
        </select>
        <input type="button" onclick="loadpage();" value="查询"/>
        <input type="button" onclick="openNew();" value="创建新意向" />
        @Html.Hidden("hidPageIndex", ViewBag.PageIndex as string)
    </p>
    <h2>我的意向列表</h2>
    <table class="table1" width="100%" border="0" cellpadding="0" cellspacing="1">
        <thead>
            <tr>
                <th width="3%"><div class="th1"></div></th>
                <th width="7%"><div class="th1">意向编码</div></th>
                <th width="7%"><div class="th1">任务编码</div></th>
                @*<th width="10%"><div class="th1">当前任务</div></th>*@
                <th width="10%"><div class="th1">客户号</div></th>
                <th width="10%"><div class="th1">客户姓名</div></th>
                <th width="10%"><div class="th1">电话</div></th>
                <th width="5%"><div class="th1">状态</div></th>
                <th width="10%"><div class="th1">创建时间</div></th>
                <th width="10%"><div class="th1">修改时间</div></th>
                <th width="10%"><div class="th1">操作人</div></th>
                <th width="14%"><div class="th1">操作</div></th>
            </tr>
        </thead>
        <tbody>
        @{
            int idx =0;
            //var dic = JydHtmlHelper.ConvertDictionaryFormEnumType<TaskManager.TaskStatus>();
            var empinfos = this.ViewBag.EmpInfos as List<EmpInfo>;
            var bll = new EmpInfoBLL();
            foreach (var item in Model)
            {
                idx++;
            <tr>
                <td>@idx</td>
                <td>@item.IntentId</td>
                <td>@(item.TaskId <= 0 ? "-" : item.TaskId.ToString())</td>
                @*<td>@(item.TaskDetailId <= 0 ? "-" : item.TaskDetailId.ToString())</td>*@
                <td>@item.CustNo</td>
                <td>@item.CustName</td>
                <td>@item.Phone</td>
                <td>@(item.Status <= 1 ? "未提交" : "已提交")</td>
                <td>@String.Format("{0:g}", item.CreateTime)</td>
                <td>@String.Format("{0:g}", item.UpdateTime)</td>
                <td>@(item.OpId.HasValue ? bll.GetEmpNameById(empinfos, item.OpId.Value) : string.Empty)</td>
                 <td>
                 @if (item.Status != 2)
                 {
                    <input type="button" onclick="openEdit(@item.IntentId);" value="修改" />
                    <input type="button" value="提交" title="提交" onclick="commit(@item.IntentId);"/>
                 }else
                 {
                     <input type="button" onclick="openDetails(@item.IntentId);" value="查看" />
                 }
                </td>
            </tr>
            }
            }
        </tbody>
    </table>
    @{
            Html.RenderPartial("_Pager");
        }
 </div>
 <script src="@Url.Content("~/skin/datepicker/WdatePicker.js")" type="text/javascript"></script>
<script type="text/javascript">
    function commit(id) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: '/intent/commit/',
            data: eval("({\"intentId\":\""+id+"\"})"),
            success: function (result) {
                var code = result.code;
                if (code == '1') {
                    window.location.reload();
                }
            },
            error: function (xhr, status, ex) {
            }
        });
    }
    function openDetails(id) {
        windowShowModalDialog("/intent/details?intentid=" + id, window, 600, 630);
    }
    function openEdit(id) {
        windowShowModalDialog("/intent/edit?intentid=" + id, window, 600, 640);
    }
    function openNew() {
        windowShowModalDialog("/intent/create/", window, 700,720);
    }
    function loadpage() {
        var start = $("#txtStartDate").val();
        var end = $("#txtEndDate").val();
        var status = $("#ddlStatus").val();
        var page = $("#hidPageIndex").val();
        if (!page) page = 1;
        url = "/intent/index?page=" + page;
        if (start) {
            url += "&start=" + start;
        }
        if (end) {
            url += "&end=" + end;
        }
        if (status) {
            url += "&status=" + status;
        }
        window.location = url;
    }
</script>
